package com.cloud.wms.ui.inside.container;

import android.content.DialogInterface;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;

import com.cloud.widget.ScanText;
import com.cloud.wms.R;
import com.cloud.wms.base.BaseBarActivity;
import com.cloud.wms.ui.inside.contract.ContainerReleaseContact;
import com.cloud.wms.ui.inside.presenter.ContainerReleasePresenter;
import com.cloud.wms.widget.dialog.AlertDialogBuilder;

import butterknife.BindView;

/**
 * Created by FC on 2021/3/10.
 * Desc：容器释放
 */
public class ReleaseActivity extends BaseBarActivity<ContainerReleasePresenter> implements ContainerReleaseContact.View {
    @BindView(R.id.scan_text)
    ScanText scanText;
    @BindView(R.id.tv_container_code)
    TextView tvContainerCode;
    @BindView(R.id.ll_container)
    LinearLayout llContainer;
    @BindView(R.id.btn_confirm)
    TextView btnConfirm;

    @Override
    protected String barTitle() {
        return "容器释放";
    }

    @Override
    protected int getResId() {
        return R.layout.activity_container_release;
    }

    @Override
    protected void initEvent() {
        initScanText(scanText);
    }

    @Override
    protected void onScanHandle(String result, int resultCode) {
        super.onScanHandle(result, resultCode);
        scanText.addHistory(result);
        AlertDialog alertDialog = new AlertDialogBuilder(this)
                .setTitle("提示")
                .setMessage("是否确认释放容器：" + result + "？")
                .setNegativeButton("取消", null)
                .setPositiveButton("确定", (dialog, which) -> mPresenter.containerRelease(result))
                .show();
        Button btn_neg = ((AlertDialog) alertDialog).getButton(AlertDialog.BUTTON_NEGATIVE);
        btn_neg.setFocusable(false);
    }


    @Override
    public void onSuccess(Message message) {
        switch (message.what) {
            case ContainerReleasePresenter.CONTAINER_RELEASE_SUCCESS:
                success("容器释放成功");
                llContainer.setVisibility(View.GONE);
                btnConfirm.setVisibility(View.GONE);
                break;
        }
    }

    @Override
    protected void setupComponent() {
        getActivityComponent().inject(this);
    }
}
